package com.zxh.mall.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author zhengxh
 * @version 1.0
 * @date 2024/5/17 - 05 - 17 - 12:12
 * @description com.zxh.mall.config
 */
@Configuration
public class MySessionConfig {

    // 自定义cookie的配置
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        cookieSerializer.setDomainName("msb.com"); // 设置session对应的一级域名
        cookieSerializer.setCookieName("msbsession");
        return cookieSerializer;
    }

    /**
     * 对存储在redis中的数据指定序列化的方式
     * @return
     */
    @Bean
    public RedisSerializer<Object>  redisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }
}
